#!/usr/bin/python
# -*- coding: UTF-8 -*-

# Created by hadoop on 17-8-9.

import unittest


class TestString(unittest.TestCase):
    def test_find(self):
        """
        test find method, subString method, test contain string method
        :return:
        """
        s = "hello,world"
        self.assertEqual(s.find(","), 5)
        sub = s[s.find(","): len(s)]
        self.assertEqual(sub, ",world")
        self.assertTrue("abc" in "abce")

    def test_join(self):
        seq = ["1", "2", "3"]
        s = ",".join(seq)
        self.assertEqual("1,2,3", s)

    def test_replace(self):
        """
        test replace
        :return:
        """
        self.assertEqual("hello,world".replace(",", "-"), "hello-world")

        ss = """ <script src="http://static.blog.csdn.net/scripts/blog_static_head.min.js" type="text/javascript">
                </script>
             """
        self.assertFalse("script" in ss.replace("script", ""))

    def test_split(self):
        s = "hello,world"
        attr = s.split(",")
        self.assertEqual(len(attr), 2)

    def test_strip(self):
        s = "   abc\n  \r"
        self.assertEqual(s.strip(), "abc")


if __name__ == '__main__':
    unittest.main()
